import vue from '@vitejs/plugin-vue'
import {
  defineConfig
} from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  ElementPlusResolver
} from 'unplugin-vue-components/resolvers'
import path from 'path'
import pxtovw from 'postcss-px-to-viewport'
const loder_pxtovw = pxtovw({
  //这里是设计稿宽度 自己修改
  viewportWidth: 1920,
  viewportUnit: 'vw'
})
export default defineConfig({
  // ...
  plugins: [
    vue(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  define: {
    'process.env': process.env
  },
  root: './',
  resolve: {
    // ↓路径别名，主要是这部分
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  envDir: path.resolve(__dirname, './env'),
  server: {
    proxy: {
      '/api': {
        target: 'http://47.103.7.16:31001/',
        changeOrigin: true,
        rewrite: (path) => path.replace(null, '')
      }
    },
    host: true,
    open: true,
    port: 3001,
  },
  css: {
    postcss: {
      // 第一方法
      plugins: [loder_pxtovw]

    }
  }


})